package com.bf.hotpoint.repository.mongo;

import static org.springframework.data.mongodb.core.query.Criteria.where;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;

import com.bf.hotpoint.domain.SimpleUser;

import static org.springframework.data.mongodb.core.query.Query.query;

@Repository
public class UserMongoRepository
{
	@Autowired
	private MongoTemplate mongoTemplate;
	
	public SimpleUser addSimpleUser(SimpleUser user)
	{
		if(user != null){
			Update update = new Update();
			update.set("nickName", user.getNickName());
			update.set("sex", user.isSex());
			mongoTemplate.upsert(query(where("uuid").is(user.getUuid())), update, SimpleUser.class);
		}
		return user;
	}
	
	public SimpleUser getSimpleUser(String uuid)
	{
		return mongoTemplate.findOne(query(where("uuid").is(uuid)), SimpleUser.class);
	}
}